<?php
use Doraemon\tools\Log;
use Doraemon\model\AdmUserType;
use Doraemon\service\LocalRank\PublicPraiseRank as sPublicPraiseRank;
use Doraemon\service\DesignerService\XinXuanDecoration as sXinXuanDecoration;
use Doraemon\model\Member;

class DecoB1Action extends ActionPlugin
{
    /**
     * @throws Exception
     */
    public function main()
    {
        Log::info('装修公司被B1接收到事件信息', $this->messageBody);
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        if (strstr($table, AdmUserType::_TABLE_NAME)) {
            $uid = $this->messageBody['data']['uid'] ?? 0;
            $eventType = $this->messageBody['type'] ?? '';
            $curQuality = $this->messageBody['data']['quality'];
            if ($eventType == 'update' || $eventType == 'insert') {
                // 获取用户身份
                $memberInfo = Member::getUserInfo($uid);
                if (!empty($memberInfo)
                    && $memberInfo['type'] == Member::AUTH_DECO_COMPANY
                    && $curQuality == AdmUserType::B1
                ) {
                    // 处理本地口碑榜,装修公司被B1永久下榜
                    sPublicPraiseRank::offlineRank(
                        $uid,
                        true,
                        Member::AUTH_DECO_COMPANY,
                        [
                            'reason' => '被B1'
                        ]
                    );

                    // 处理装修搭子H5用户展示状态字段
                    sXinXuanDecoration::syncShowStatusCompany($uid);
                }
            }
        }
        Log::info('接收到装修公司被B1的事件', compact('uid', 'message'));
        $this->setSuccess();
    }
}